<template>
	<view class="user-list-detail">
		<UserHead :info="headObj"></UserHead>
    <view class="detail_list">
      <template v-if="listLen">
        <DetailBlock
          v-for="item in list"
          :key="item.Id"
          :type="pageType"
          :info="item"
        ></DetailBlock>
      </template>
      <!-- <AppNoData v-else></AppNoData> -->
    </view>
	</view>
</template>

<script>
  import {mapState} from 'vuex';
  import UserHead from './components/UserHead/index.vue'
  import DetailBlock from './components/DetailBlock/index.vue'
	export default {
		name: 'UserListDetail',
		components:{
      UserHead,
      DetailBlock
		},
		data () {
			return {
        token: '',
        pageType:'score',
        title:'红绿码变化',
        headObj:{
          name:'',
          company:'',
          face:''
        },
				userObj:{},
        list:[],
        showList:[],
        pageNumb:20,
        showPage:0
			}
		},
    computed:{
      listLen(){
        return this.list.length
      }
    },
		onLoad(e) {
			console.log(e)
      this.pageType = e.pageType
      this.userObj = JSON.parse(e.user)
      this.headObj.name = this.userObj.StaffName
      this.headObj.company = this.userObj.CompanyName
      switch(this.pageType){
        case 'study':
          this.title = '最近减分记录'
          break;
        case 'score':
          this.title = '最近红绿码变化记录'
          break;
      }
      uni.setNavigationBarTitle({
        title:this.title
      })
      this.dataInit()
      // 页面pv事件埋点
      this.$aplus.aplus_queue.push({
        'action':'aplus.sendPV',
        'arguments':[{
          is_auto: false
        }, {
          sapp_id:'19344',//isv根据实际填写自己应用的参数
          sapp_name:'zhongdianchelian',//isv根据实际填写自己应用的参数
          // 自定义PV参数key-value键值对，以下内容必填，根据应用实际情况设置。
          page_id: 'studyDetail',//isv根据实际填写自己应用的参数
          page_name: '最近减分记录',//isv根据实际填写自己应用的参数
          page_url: 'pages/studyDetail/studyDetail'//isv根据实际填写自己应用的参数
        }]
      })
		},
		onShow () {},
		onHide () {},
		onUnload () {},
    onReachBottom(){
      // console.log('dddd')
      // this.addShowList()
    },
		methods: {
      dataInit(){
        uni.getStorage({
          key: 'token',
          success: (res) => {
            this.token = res.data
            this.getList()
            this.getUserFace()
          }
        })
      },
      addShowList(){
        if(this.listLen == 0) return
        if(this.list[0]=='del' && this.list.length == 1) return
        this.showPage += 1
        this.showList.push(...this.list.splice(0,this.pageNumb))
      },
			getList(){
        uni.showLoading()
        let api = 'Muck/GetStaffScoreList'
        let params = {
          Token:this.token,
          StaffId:this.userObj.StaffId || this.userObj.StaffIdNew
        }
        if(this.pageType == 'score'){
          api = 'Muck/GetStaffQrcodeListNew'
          params.StaffId = this.userObj.StaffId
        }
       
        this.$http.get(api,params)
        .then(res=>{
          uni.showToast({
            title:res.result.Count + '条信息'
          })
          this.list = res.result.List
          uni.hideLoading()
          // this.addShowList()
        }).catch(err=>{
          uni.hideLoading()
          uni.showToast({
            title: '请求数据出错'
          })
          // this.$utils.comHttpErrMsg('列表详情',err)
        })
      },
      getUserFace(){
        this.$http.get('Muck/getStaffFace',{
          Token:this.token,
          StaffId:this.userObj.StaffId || this.userObj.StaffIdNew
        }).then(res=>{
          this.headObj.face = res.result.Face
        }).catch(err=>{
          uni.showToast({
            title:'人脸获取失败,'+err.result,
            icon:'none'
          })
        })
      },
		}
	}
</script>

<style lang="scss">
	.user-list-detail{
    background: #F5F5F5;
    min-height: 100vh;
    .detail_list{
      padding:32rpx;
      box-sizing: border-box;
    }
  }
</style>
